﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"	
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    xmlns:core="clr-namespace:System;assembly=mscorlib"	
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"  
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"
    xmlns:Factory_Core="clr-namespace:BadHabit.Factory;assembly=FactoryCore"
    
    xmlns:props="clr-namespace:BadHabit.Factory.Properties"
    
	x:Class="BadHabit.Factory.Controls.ProjectListBox"
	x:Name="UserControl"	
    DataContextChanged="UserControl_DataContextChanged"
    HorizontalContentAlignment="Stretch"
    VerticalContentAlignment="Stretch"
    HorizontalAlignment="Stretch"
    
    Loaded="UserControl_Loaded"
        
    
    
    
    FocusManager.FocusedElement="{Binding ElementName=projectFilterTextBox}"
            
    SnapsToDevicePixels="True">

    <UserControl.CommandBindings>
        <CommandBinding Command="ApplicationCommands.New" Executed="New_Executed" />
    </UserControl.CommandBindings>


    <UserControl.Resources>                
       
        <!-- DATA TEMPLATE FOR CLIENT ITEM -->
        <DataTemplate x:Key="ClientSelectedItemTemplate" >
            <WrapPanel>                
                <Image x:Name="clientIcon" Source="/Images/Icons/Client.gif" Stretch="None" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding}" TextWrapping="Wrap"/>                                
            </WrapPanel>            
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding}" Value="">
                    <Setter TargetName="clientIcon" Property="Image.Visibility" Value="Hidden"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>


        <!-- DATA TEMPLATE FOR PROJECT ITEM -->
        <DataTemplate x:Key="ProjectItemTemplate" >
            
				    <Grid>			     
    			        <Grid.ColumnDefinitions>
    				        <ColumnDefinition Width="40"  />
    				        <ColumnDefinition Width="*" />    				     				   
    			        </Grid.ColumnDefinitions>
        			
                        <Image
                            DataContext="{Binding Status, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:ProjectStatus} }"
                            Style="{StaticResource ProjectStatusImage}" Grid.Column="0" VerticalAlignment="Top"/>
                        <Image Source="/Images/Toolbar/SuspendProject.png" Grid.Column="0" Stretch="Uniform" Width="16" Height="16" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,16,0,0">
                            <Image.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsSuspended}" Value="False">
                                            <Setter Property="Image.Visibility" Value="Hidden"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>

                        <Grid Grid.Column="1" >                          
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="*"/>                                
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            
                            <Grid Grid.Row="0" Margin="0,0,0,2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Path=ProjectName}" Style="{StaticResource ProjectListItemTitle}" Grid.Column="0" TextWrapping="Wrap"/>
                                <TextBlock Text="{Binding  Path=ProjectNumber}" Style="{StaticResource ProjectListItemTitle}" Grid.Column="1" TextAlignment="Right" DockPanel.Dock="Right" Foreground="Gray" FontWeight="Normal" />                           
                            </Grid>
                            
    			            <TextBlock Text="{Binding Path=ClientName}" Grid.Row="1" Foreground="Gray"/>
                            
                            <WrapPanel Orientation="Horizontal" Grid.Row="2">
                                <TextBlock Text="{Binding Path=StartDate, StringFormat='{}{0:d} - '}"  Foreground="Gray" VerticalAlignment="Center" />                                    
                                <TextBlock  Text="{Binding Path=EstimatedStartDate, StringFormat='{}{0:d} - '}"  Foreground="Gray" VerticalAlignment="Center" >
                                    <TextBlock.Style>
                                        <Style  BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="{x:Type TextBlock}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Status}" Value="5">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="6">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="7">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="8">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="9">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="10">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                                <TextBlock  Text="{Binding Path=EstimatedEndDate, StringFormat='{}{0:d}'}"  Foreground="Gray" VerticalAlignment="Center" >
                                    <TextBlock.Style>
                                        <Style BasedOn="{StaticResource {x:Type TextBlock}}"  TargetType="{x:Type TextBlock}">                                            
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Status}" Value="8">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="9">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Status}" Value="10">
                                                    <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                                </DataTrigger>                                                
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                                <TextBlock  Text="{Binding Path=EndDate, StringFormat='{}{0:d}' }" Foreground="Gray" VerticalAlignment="Center" />                                    
                            </WrapPanel>
                            
                            <!--<DockPanel Grid.Row="3">
                                <TextBlock Text="{Binding TotalSize, StringFormat='{}{0} pts'}" DockPanel.Dock="Left" VerticalAlignment="Center" Foreground="Gray"/>                                                             
                            </DockPanel>-->
                    <TextBlock Grid.Row="3" FontFamily="{StaticResource BasicFont}" FontSize="{StaticResource BasicFontSize}" PreviewMouseLeftButtonDown="TextBlock_PreviewMouseLeftButtonDown">                        
                        <Image Source="/Images/ToolBar/Folder.png" Stretch="Uniform" Width="16" Height="16" />    
                        <Hyperlink BaselineAlignment="Center">                            
                            <TextBlock Text="{x:Static props:Resources.Go_to_project_folder}"/>                            
                        </Hyperlink>
                    </TextBlock>
                        
                        </Grid>
                <Grid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="{x:Static props:Resources.Copy_Shortcut}" Click="CopyShortCut_Click"/>
                    </ContextMenu>

                </Grid.ContextMenu>
            </Grid>
			
                
                    
            
</DataTemplate>

    </UserControl.Resources>
    
    <Border
        CornerRadius="0,5,0,0"
        BorderThickness="1,1,1,0"        
        Background="White"
        BorderBrush="{StaticResource ProjectPanelBorderBrush}">
        <Border.BitmapEffect>
            <DropShadowBitmapEffect Direction="300" Color="LightGray" ShadowDepth="3" Softness=".3"   />
        </Border.BitmapEffect>
        
        <!-- THE CONTROL LAYOUT -->
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="contentColumn" Width="Auto"/>
                <ColumnDefinition Name="headerColumn" Width="Auto"/>
            </Grid.ColumnDefinitions>

              

            <!-- HERE WE STACK THE FILTER AND THE LIST -->
            <Grid VerticalAlignment="Stretch" Grid.Column="0" Width="300"  >

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <!-- FILTER PANEL -->
                <!--<Border Grid.Row="0"  Background="White" Padding="3">-->
                    <Grid Grid.Row="0" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource Label}" Text="{x:Static props:Resources.Search}"/>
                        <TextBox
                            
                            Grid.Column="1" Grid.Row="0" Style="{StaticResource FilterTextBox}"
                            x:Name="projectFilterTextBox" TextChanged="projectFilterTextBox_TextChanged" HorizontalAlignment="Stretch" />

                        <TextBlock Grid.Column="0" Grid.Row="1" Text="{x:Static props:Resources.at}" Style="{StaticResource Label}"/>

                        <BadHabit_WPFTools:ComboBox Grid.Column="1" Grid.Row="1" x:Name="projectFilterComboBox" HorizontalAlignment="Stretch" SelectionChanged="projectFilterComboBox_SelectionChanged"
                          Style="{StaticResource FormComboBox}" DropDownClosed="filterComboBox_DropDownClosed">
                            <ComboBoxItem x:Name="projectsImInComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Projects_I_am_in}"/>
                            </ComboBoxItem>
                            <ComboBoxItem x:Name="runningProjectsComboBoxItem">
                                    <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Running_projects}"/>
                            </ComboBoxItem>                            
                            <ComboBoxItem x:Name="taskForMeProjectsComboBoxItem" >
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Projects_with_tasks_for_me}"/>
                            </ComboBoxItem>                            
                            <ComboBoxItem x:Name="allProjectsComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.All_projects}"/>
                            </ComboBoxItem>
                            <Separator/>
                            <ComboBoxItem x:Name="scheduledProjectsComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Scheduled_projects}"/>
                            </ComboBoxItem>
                            <ComboBoxItem x:Name="oportunitesProjectsComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Oportunities}"/>
                            </ComboBoxItem>
                            <Separator/>
                            <ComboBoxItem x:Name="closedProjectsComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Closed_projects}"/>
                            </ComboBoxItem>
                            <ComboBoxItem x:Name="stillToPayProjectsComboBoxItem">
                                <TextBlock Padding="21,0,0,0" Text="{x:Static props:Resources.Still_to_pay_projects}"/>
                            </ComboBoxItem>
                            <ComboBoxItem x:Name="inDebitProjectsComboBoxItem">
                                <WrapPanel>
                                    <Image Source="/Images/Icons/prjAlertPayment.gif" Stretch="None" Margin="0,0,5,0" />
                                    <TextBlock Text="{x:Static props:Resources.In_debit_projects}"/>
                                </WrapPanel>
                            </ComboBoxItem>


                        </BadHabit_WPFTools:ComboBox>

                        <TextBlock Grid.Column="0" Grid.Row="2" Style="{StaticResource Label}" Text="{x:Static props:Resources.From}"/>

                        <BadHabit_WPFTools:ComboBox
                          Grid.Column="1" Grid.Row="2"
                          x:Name="clientFilterComboBox"                                  
                          SelectedItemTemplate="{StaticResource ClientSelectedItemTemplate}"                                  
                          SelectionChanged="clientFilterComboBox_SelectionChanged"                              
                          Style="{StaticResource FormComboBox}"
                          HorizontalAlignment="Stretch"
                          MaxDropDownHeight="500"
                          IsTextSearchEnabled="True"
                          DropDownClosed="filterComboBox_DropDownClosed"                                 
                          />



                    </Grid>

                <!--</Border>-->
                
            
                

                <ListBox    Grid.Row="1"
                    Name="listBox"
                    HorizontalAlignment="Stretch"             
                            
                    PreviewMouseLeftButtonUp="Grid_MouseLeftButtonUp"
                     
                    HorizontalContentAlignment="Stretch"
                    VerticalContentAlignment="Stretch"                     
                    ItemContainerStyle="{StaticResource HorizontalDividedListBoxItem}"
                    ItemTemplate="{StaticResource ProjectItemTemplate}"                                                      
                    BorderThickness="0,0,0,0"                                    
                    Background="{StaticResource ControlContentBrush}"   
                    Height="Auto"
                    ScrollViewer.CanContentScroll="False"
                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    ScrollViewer.VerticalScrollBarVisibility="Hidden"                            
                    SelectionChanged="listBox_SelectionChanged"    
                    
                    
                    
                 >


                </ListBox>

                <Grid
                x:Name="noProjectFoundGrid"
                Visibility="Hidden"
                Grid.Row="1"
                Margin="5"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="20"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock
                        Grid.Column="1" Grid.Row="0"
                        TextWrapping="Wrap" Margin="0,15,0,0" Text="{x:Static props:Resources.Projects_not_found}"/>                        
                    <Image
                        Grid.Column="0" Grid.Row="1"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Margin="0,15,0,0"
                        Source="/Images/Icons/information.png" Width="16" Height="16" Stretch="Uniform"/>
                    <TextBlock
                        Grid.Column="1" Grid.Row="1"
                        VerticalAlignment="Top"
                        Foreground="Gray" TextWrapping="Wrap" Margin="0,15,0,0"
                        Text="{x:Static props:Resources.Projects_not_found_tip}"/>                                            
                    <Image
                        BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                        Grid.Column="0" Grid.Row="2"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Margin="0,15,0,0"
                        Source="/Images/Icons/information.png" Width="16" Height="16" Stretch="Uniform"/>
                    <TextBlock
                        BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                        Grid.Column="1" Grid.Row="2"
                        VerticalAlignment="Top"
                        Foreground="Gray" TextWrapping="Wrap"  Margin="0,15,0,0"
                        Text="{x:Static props:Resources.Projects_not_found_create_project_tip}"/>
                        
                    <Button
                        BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                        Grid.ColumnSpan="2" Grid.Row="3"         
                        Command="ApplicationCommands.New"
                        Margin="0,15,0,0" Width="100" Content="{x:Static props:Resources.New_Project}"/>

                </Grid>


                <BadHabit_Factory_Controls:SmartScroll Grid.Row="1" ScrollDirection="Up" PanelName="listBox" RepeatButtonStyle="{StaticResource ScrollUpButton}" />
                <BadHabit_Factory_Controls:SmartScroll Grid.Row="1" ScrollDirection="Down" PanelName="listBox" RepeatButtonStyle="{StaticResource ScrollDownButton}" />

            <Grid.Style>
                <Style>

                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=headerBorder, Path=IsChecked}" Value="False">
                            <Setter Property="Grid.Visibility" Value="Visible"/>
                            <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=listBox}"/>                            
                            </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=headerBorder, Path=IsChecked}" Value="True">
                            <Setter Property="Grid.Visibility" Value="Collapsed"/>
                        </DataTrigger>
                            
                   </Style.Triggers>

                </Style>

            </Grid.Style>

        </Grid>
        

            <!-- THE HEADER -->
            <Border     Grid.Column="1"
                    BorderThickness="0"                    
                    Height="25"                                        
                    Width="Auto"                             
                    VerticalAlignment="Stretch"             
                    CornerRadius="5,0,0,0"
                    Background="{StaticResource GradientSilverBrush}">

                <Border.LayoutTransform>
                    <RotateTransform Angle="90"/>
                </Border.LayoutTransform>

                <ToggleButton x:Name="headerBorder">

                    <WrapPanel VerticalAlignment="Center" HorizontalAlignment="Left">
                        <Image Source="/Images/Icons/lupe.png" Stretch="Uniform" Width="16" Height="16" Margin="0,0,5,0" />
                        <TextBlock Text="{x:Static props:Resources.Project_search}" Margin="0,0,5,0" Foreground="{StaticResource DarkTextBrush}" />
                    </WrapPanel>
                </ToggleButton>



            </Border>


        </Grid>

    </Border>

   

            
        
        
        


     
</UserControl>